﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
using System.Drawing.Imaging;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Web.SessionState;
using System.ComponentModel;
using System.Data;
using System.Web.UI.HtmlControls;

namespace iResume
{
    public partial class JobseekerUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!Page.IsPostBack)
            {
                catddl.Focus();

                ArrayList jsUpdate = new ArrayList();
                string email = (string)(Session["username"]);
                if (email == null)
                {
                    Response.Redirect("loginpage.aspx");
                }
                jsUpdate = DBManager.retrievejs(email);
                JobSeeker Update = new JobSeeker();
                Update = (JobSeeker)jsUpdate[0];
                Image1.ImageUrl = "jobSeekerDisplayImg.ashx?id=" + Update.EmailAdd;
                fullname.Text = Update.FullName;
                catddl.Text = Update.Jobcategory.ToString();
                introd.Text = Update.Profile;
                educ.Text = Update.Education;
                skill.Text = Update.Skills;
                exper.Text = Update.Workexperience;



            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
  
        }

        protected void skill_TextChanged(object sender, EventArgs e)
        {

        }

        protected void educ_TextChanged(object sender, EventArgs e)
        {

        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            string username = (string)(Session["username"]);
            string fullName = fullname.Text;
            string category = catddl.SelectedItem.Text;
            string profile = introd.Text;
            string education = educ.Text;
            string skills = skill.Text;
            string experience = exper.Text;

            string imageType = FileUploadImage.PostedFile.ContentType;
            byte[] imageData = new byte[FileUploadImage.PostedFile.InputStream.Length + 1];
            FileUploadImage.PostedFile.InputStream.Read(imageData, 0, imageData.Length);

            //Upload Doc

            string filePath = FileUploadDoc.Value;
            string filename = Path.GetFileName(filePath);

            if (FileUploadImage.PostedFile.FileName != "")
            {
                FileInfo info = new FileInfo(FileUploadDoc.PostedFile.ContentType);
                byte[] content = new byte[FileUploadDoc.PostedFile.InputStream.Length + 1];
                FileUploadDoc.PostedFile.InputStream.Read(content, 0, content.Length);


                JobSeeker js = new JobSeeker(category, profile, education, skills, experience, username, fullName, imageData, filename, content);
                DBManager.updateJsResume(js);

                catddl.Text = "";
                introd.Text = "";
                educ.Text = "";
                skill.Text = "";
                exper.Text = "";


                Response.Redirect("Loginjobseeker.aspx");
            }
            else
            {
                FileInfo info = new FileInfo(FileUploadDoc.PostedFile.ContentType);
                byte[] content = new byte[FileUploadDoc.PostedFile.InputStream.Length + 1];
                FileUploadDoc.PostedFile.InputStream.Read(content, 0, content.Length);


                JobSeeker js = new JobSeeker(category, profile, education, skills, experience, username, fullName, imageData, filename, content);
                DBManager.updateJsResume1(js);

                catddl.Text = "";
                introd.Text = "";
                educ.Text = "";
                skill.Text = "";
                exper.Text = "";


                Response.Redirect("Loginjobseeker.aspx");
            }

        }
    }
}